<?php
$ch = curl_init("http://beta.openbadges.org/displayer/convert/email");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "email=" . urlencode("marco.grazioli0@gmail.com"));
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$data = curl_exec($ch);

echo "Dati JSON<br>";
echo $data;
echo "<br>Output di json_decode()<br>";
echo var_dump(json_decode($data)). "<br>";;

echo "<br>";

echo "Headers risposta HTTP<br>";
$headers = get_headers("http://localhost/openbadges/img/badges_png/unisalentoeng.png", 1);
echo var_dump($headers) . "<br>";
if (isset($headers["Content-Type"]))
	echo "Content-Type: " . $headers["Content-Type"] . "<br>";

echo "<br>";

echo "Headers risposta HTTP da localhost:8888 con asserzione non esistente<br>";
$headers = get_headers("http://localhost:8888/baker?assertion=http://localhost/non_existing.json", 1);
echo var_dump($headers) . "<br>";
if (isset($headers["Content-Type"]))
	echo "Content-Type: " . $headers["Content-Type"] . "<br>";

echo "<br>";

echo "Headers risposta HTTP da localhost:8888 con asserzione mal formattata<br>";
$headers = get_headers("http://localhost:8888/baker?assertion=http://localhost/openbadges/json/assertions/firstbadge.json", 1);
echo var_dump($headers) . "<br>";
if (isset($headers["Content-Type"]))
	echo "Content-Type: " . $headers["Content-Type"] . "<br>";

echo "<br>";

echo "Headers risposta HTTP da localhost:8888 con asserzione ben formattata<br>";
$headers = get_headers("http://localhost:8888/baker?assertion=http://localhost/openbadges/json/assertions/badge_3d254e.json", 1);
echo var_dump($headers) . "<br>";
if (isset($headers["Content-Type"]))
	echo "Content-Type: " . $headers["Content-Type"] . "<br>";

echo "<br>";

echo "Headers risposta HTTP da beta.openbadges.org con asserzione non verificabile<br>";
$headers = get_headers("http://beta.openbadges.org/baker?assertion=http://localhost/openbadges/json/assertions/firstbadge.json", 1);
echo var_dump($headers) . "<br>";
if (isset($headers["Content-Type"]))
	echo "Content-Type: " . $headers["Content-Type"] . "<br>";

$ch = curl_init("http://beta.openbadges.org/baker?assertion=http://localhost/openbadges/json/assertions/firstbadge.json");
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$data = curl_exec($ch);

echo "Dati JSON<br>";
echo $data;
echo "<br>Output di json_decode()<br>";
echo var_dump(json_decode($data)). "<br>";;
?>
